package com.kady.controller.menu;

import com.alibaba.fastjson.JSON;
import com.kady.contant.BeanFactoryConstant;
import com.kady.controller.BaseServlet;
import com.kady.entity.Menu;
import com.kady.entity.ResultVO;
import com.kady.factory.BeanFactory;
import com.kady.service.MenuService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/backend/menu")
public class MenuController extends BaseServlet {

    private MenuService menuService = (MenuService)BeanFactory.getBean(BeanFactoryConstant.MENU_SERVICE);

    /**
     * 获取菜单列表
     */
    public void list (HttpServletRequest req, HttpServletResponse resp) throws SQLException, IOException {
        List<Menu> menuList = menuService.getMenuList();
        ResultVO resultVO = new ResultVO(true,"请求成功",menuList);
        resp.getWriter().write(JSON.toJSONString(resultVO));
    }

}
